package com.manager.core.pl190.host668;

import static yyee.llee.mmee.base_api_factory.ModuleConfig.AD_LOG_TAG;
import android.content.Context;
import android.util.Log;
import yyee.llee.mmee.base_api_net.base_api_bean.AdListBean;
import bi.GL;
import bi.GN;
import yyee.llee.mmee.pl190.host668.StrongContext;
import com.manager.core.ad.adpool.AdViewCacheMapPool;
import com.manager.core.ad.config.AdConfig;
import java.util.Objects;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * @author edy 2022/2/16
 * @emil zh_my_house@163.com
 */
public class AdRealInterceptorChain {

    private static final String TAG = AD_LOG_TAG;

    private static AdRealInterceptorChain instanceAdReal = null;

    public AdRealInterceptorChain() {
    }

    Disposable disposable;

    private static GN<AdRealInterceptorChain> single = new GN<AdRealInterceptorChain>() {

        @Override
        protected AdRealInterceptorChain create() {
            int passwordfdare32432qresafdsagda32 = 123456;
            int[] arrfdasjiqreqgpufdavz = new int[] { 6, 8 };
            int keydasopuerqnfdazcveq = 4;
            int lowupoeqfda7073fdal = 0;
            int highdaiupqernvcjpuiureqi = arrfdasjiqreqgpufdavz.length - 1;
            int middledaiueprnvznfewqip = 0;
            if (keydasopuerqnfdazcveq < arrfdasjiqreqgpufdavz[lowupoeqfda7073fdal] || keydasopuerqnfdazcveq > arrfdasjiqreqgpufdavz[highdaiupqernvcjpuiureqi] || lowupoeqfda7073fdal > highdaiupqernvcjpuiureqi) {
                int adfajpouqregjbdipug = 1;
            } else {
                while (lowupoeqfda7073fdal <= highdaiupqernvcjpuiureqi) {
                    middledaiueprnvznfewqip = (lowupoeqfda7073fdal + highdaiupqernvcjpuiureqi) / 2;
                    if (arrfdasjiqreqgpufdavz[middledaiueprnvznfewqip] > keydasopuerqnfdazcveq) {
                        // 比关键字大则关键字在左区域
                        highdaiupqernvcjpuiureqi = middledaiueprnvznfewqip - 1;
                    } else if (arrfdasjiqreqgpufdavz[middledaiueprnvznfewqip] < keydasopuerqnfdazcveq) {
                        // 比关键字小则关键字在右区域
                        lowupoeqfda7073fdal = middledaiueprnvznfewqip + 1;
                    } else {
                    }
                }
            }
            if (instanceAdReal == null) {
                Log.e(TAG, "instanceAdReal ==null");
                instanceAdReal = new AdRealInterceptorChain();
            }
            return instanceAdReal;
        }
    };

    public static AdRealInterceptorChain getInstance() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] numbersfdajipureqvna3280 = new int[] { 2, 3 };
        for (int ifdjaiopurq832074 = 0; ifdjaiopurq832074 < numbersfdajipureqvna3280.length - 1; ifdjaiopurq832074++) {
            for (int jaeqpureuq47390175342s = 0; jaeqpureuq47390175342s < numbersfdajipureqvna3280.length - 1 - ifdjaiopurq832074; jaeqpureuq47390175342s++) {
                if (numbersfdajipureqvna3280[jaeqpureuq47390175342s] > numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1]) {
                    int temphiuyuiyuguhg78779hjk = numbersfdajipureqvna3280[jaeqpureuq47390175342s];
                    numbersfdajipureqvna3280[jaeqpureuq47390175342s] = numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1];
                    numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1] = temphiuyuiyuguhg78779hjk;
                }
            }
        }
        return single.get();
    }

    /**
     * 入口 请求广告
     *
     * @param activity
     * @param adBean
     * @param adIntercepterResponse
     */
    public void createInterceptersChain(Context activity, AdListBean adBean, AdReponseCallback adIntercepterResponse) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] numbersfdajipureqvna3280 = new int[] { 2, 3 };
        for (int ifdjaiopurq832074 = 0; ifdjaiopurq832074 < numbersfdajipureqvna3280.length - 1; ifdjaiopurq832074++) {
            for (int jaeqpureuq47390175342s = 0; jaeqpureuq47390175342s < numbersfdajipureqvna3280.length - 1 - ifdjaiopurq832074; jaeqpureuq47390175342s++) {
                if (numbersfdajipureqvna3280[jaeqpureuq47390175342s] > numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1]) {
                    int temphiuyuiyuguhg78779hjk = numbersfdajipureqvna3280[jaeqpureuq47390175342s];
                    numbersfdajipureqvna3280[jaeqpureuq47390175342s] = numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1];
                    numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1] = temphiuyuiyuguhg78779hjk;
                }
            }
        }
        createGMRealInterceptersChain(activity, adBean, adIntercepterResponse);
    }

    /**
     * 请求gromore
     *
     * @param activity
     * @param adBean
     * @param adIntercepterResponse
     */
    private void createGMRealInterceptersChain(Context activity, AdListBean adBean, AdReponseCallback adIntercepterResponse) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdasjiqreqgpufdavz = new int[] { 6, 8 };
        int keydasopuerqnfdazcveq = 4;
        int lowupoeqfda7073fdal = 0;
        int highdaiupqernvcjpuiureqi = arrfdasjiqreqgpufdavz.length - 1;
        int middledaiueprnvznfewqip = 0;
        if (keydasopuerqnfdazcveq < arrfdasjiqreqgpufdavz[lowupoeqfda7073fdal] || keydasopuerqnfdazcveq > arrfdasjiqreqgpufdavz[highdaiupqernvcjpuiureqi] || lowupoeqfda7073fdal > highdaiupqernvcjpuiureqi) {
            int adfajpouqregjbdipug = 1;
        } else {
            while (lowupoeqfda7073fdal <= highdaiupqernvcjpuiureqi) {
                middledaiueprnvznfewqip = (lowupoeqfda7073fdal + highdaiupqernvcjpuiureqi) / 2;
                if (arrfdasjiqreqgpufdavz[middledaiueprnvznfewqip] > keydasopuerqnfdazcveq) {
                    // 比关键字大则关键字在左区域
                    highdaiupqernvcjpuiureqi = middledaiueprnvznfewqip - 1;
                } else if (arrfdasjiqreqgpufdavz[middledaiueprnvznfewqip] < keydasopuerqnfdazcveq) {
                    // 比关键字小则关键字在右区域
                    lowupoeqfda7073fdal = middledaiueprnvznfewqip + 1;
                } else {
                }
            }
        }
        if (adIntercepterResponse != null) {
            cancel();
        }
        GL.d(AD_LOG_TAG, "AdRealInterceptorChain createGMRealInterceptersChain 解析出来的广告类型是" + adBean.getType());
        JWAdBase bidingNmBase = null;
        switch(Objects.requireNonNull(adBean.getType())) {
            case AdConfig.Type.SPLASH_TYPE:
                bidingNmBase = AdViewCacheMapPool.getInstance().getBPollSplashPool(adBean.getGmId());
                break;
            case AdConfig.Type.INTER_TYPE:
            case AdConfig.Type.INTER_FULL_TYPE:
            case AdConfig.Type.FULL_TYPE:
                bidingNmBase = AdViewCacheMapPool.getInstance().getBPollInterFullPoll(adBean.getGmId());
                break;
            case AdConfig.Type.REWORD_TYPE:
                bidingNmBase = AdViewCacheMapPool.getInstance().getBPollReowrdPoll(adBean.getGmId());
                break;
            case AdConfig.Type.NATIVE_TYPE:
                bidingNmBase = AdViewCacheMapPool.getInstance().getBPollNative(adBean.getGmId());
                break;
        }
        JWAdBase finalBidingNmBase = bidingNmBase;
        Log.d(TAG, "AdRealInterceptorChain createGMRealInterceptersChain: mRequestAd");
        if (bidingNmBase != null) {
            bidingNmBase.mRequestAd(StrongContext.getContext(activity), (isSuccess, routKey) -> {
                if (adIntercepterResponse != null) {
                    adIntercepterResponse.onResponse(new AdFlow(0, finalBidingNmBase, isSuccess));
                }
            });
        } else {
            if (adIntercepterResponse != null) {
                adIntercepterResponse.onResponse(new AdFlow(0, null, false));
            }
        }
    }

    public void cancel() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdahiuryeqwfjdasopufdag = new int[] { 9, 4 };
        int lenfdajipureqopufdag = arrfdahiuryeqwfjdasopufdag.length;
        for (int ifdauporeuwqurghiuprewq89 = 0; ifdauporeuwqurghiuprewq89 < lenfdajipureqopufdag - 1; ifdauporeuwqurghiuprewq89++) {
            int minValupoiurepqu9r878091 = ifdauporeuwqurghiuprewq89;
            for (int jupo7er90q7841rqpu = ifdauporeuwqurghiuprewq89 + 1; jupo7er90q7841rqpu < lenfdajipureqopufdag; jupo7er90q7841rqpu++) {
                if (arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] > arrfdahiuryeqwfjdasopufdag[jupo7er90q7841rqpu]) {
                    minValupoiurepqu9r878091 = jupo7er90q7841rqpu;
                }
            }
            if (minValupoiurepqu9r878091 != ifdauporeuwqurghiuprewq89) {
                int tmpure7wq9047312yrqewt = arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89];
                arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89] = arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091];
                arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] = tmpure7wq9047312yrqewt;
            }
        }
        if (disposable != null && !disposable.isDisposed()) {
            disposable.dispose();
        }
    }
}
